package Repository;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;

import model.Account;
import model.Approved;
import model.Opportunity;
import model.Quote;


public class OpportunityRepository extends Repository{
	
	private static HashMap<Long,Opportunity> opportunityMap = new HashMap<Long,Opportunity>();
	
	//private OpportunityRepository(){}
	
	/*static{
		Opportunity opportunity=new Opportunity();
		opportunity.setName("Mythri");
		opportunity.setQuote(new Quote());
		Calendar cal = Calendar.getInstance();
		cal.set(2009, 10, 11);
		opportunity.setClosedDate(cal.getTime());
		opportunity.setDescription("The Lead is Approved.");
		opportunity.setCurrentState(new Approved());
		opportunity.setAccount(new Account());
		opportunityMap.put(new Long(1),opportunity);
		
		opportunity=new Opportunity();
		opportunity.setName("Aarthi");
		opportunity.setQuote(new Quote());
		cal.set(2009, 10, 15);
		opportunity.setClosedDate(cal.getTime());
		opportunity.setDescription("The Lead is Approved.");
		opportunity.setCurrentState(new Approved());
		opportunity.setAccount(new Account());
		opportunityMap.put(new Long(2),opportunity);
		
		opportunity=new Opportunity();
		opportunity.setName("Sandhya");
		opportunity.setQuote(new Quote());
		cal.set(2009, 10, 2);
		opportunity.setClosedDate(cal.getTime());
		opportunity.setDescription("The Lead is Approved.");
		opportunity.setCurrentState(new Approved());
		opportunity.setAccount(new Account());
		opportunityMap.put(new Long(3),opportunity);
		
		opportunity=new Opportunity();
		opportunity.setName("Dhara");
		opportunity.setQuote(new Quote());
		cal.set(2009, 11, 31);
		opportunity.setClosedDate(cal.getTime());
		opportunity.setDescription("The Lead is Approved.");
		opportunity.setCurrentState(new Approved());
		opportunity.setAccount(new Account());
		opportunityMap.put(new Long(4),opportunity);
	}*/
	
	public Object retrieve(Long id) {
		/*if (smsobjType.equals(SMSConstants.OPPORTUNITY))
		{
			if(Type.equals("Qualified"))
			{
				return Opportunity.get(information.LeadType.equals("Qualified"));
			}
			else if(Type.equals("Prepared"))
			{
				return Opportunity.get(information.LeadType.equals("Prepared"));	
			}
			else if(Type.equals("ProduceQuoted"))
			{
			return Opportunity.get(information.LeadType.equals("ProduceQuoted"));
		
			}
			else if(Type.equals("ApproveQuoted"))
			{
			return Opportunity.get(information.LeadType.equals("ApproveQuoted"));
		
			}
		}	*/
		
		return opportunityMap.get(id);
	}
	
	
	public void delete(Long id) {
		
	}
	
	public void insert(Long id,Object obj) {
		opportunityMap.put(id, (Opportunity)obj);
				
	}
	
	public void update(Long id, Object updatedObj) {
		opportunityMap.remove(id);
		opportunityMap.put(id, (Opportunity)updatedObj);
		
		
	}


	@Override
	public Object retrieve(String objectType, String ruleType) {
		// TODO Auto-generated method stub
		return null;
	}


	@Override
	public List retrieve(String State) {
		List list =new ArrayList();
		Collection<Opportunity> c = opportunityMap.values();
		
		
			for(Opportunity opportunity : c )
			{	
				if(opportunity.getCurrentState().getStateName().equalsIgnoreCase(State))
				{
					list.add(opportunity);
				}				
			}
			
	return list;
	}


	@Override
	public boolean find(String objName) {
		// TODO Auto-generated method stub
		return false;
	}


	@Override
	public Collection retrieveAll() {
		// TODO Auto-generated method stub
		return null;
	}
	
	
}
